<template>
	<view class="box">
		<view v-for="(item,index) in videolist" :key="item._id" :data-uid="item._id">
			<my-piece :item="item" @deletevideo="deletevideo"></my-piece>
		</view>
		<u-modal @cancel="cancel" @confirm="confirm" :showCancelButton="true" confirmText="确认取消" :show="immediate"
			title="取消屏蔽" :content='content'></u-modal>
			
			<view class="pb" v-if="isshow">
				<text>暂无屏蔽内容</text>
			</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				isshow:false,
				user_id: '',
				videolist: [],
				immediate: false,
				content: '',
				vide_id:""
			};
		},
		onLoad() {
			this.user_id = uniCloud.getCurrentUserInfo().uid
			this.getlist()
		},
		methods: {
			cancel() {
				this.immediate = false
			},
			confirm() {
				this.immediate = false

				// 	let templist=this.videolist.report.splice(tempindex,1)
				// console.log(tempindex,templist)
				uni.showLoading({
					
				})
				db.collection("video-articles").where({
					_id: this.vide_id
				}).get().then(res => {
					console.log(res, "ss")
					let tempindex = res.result.data[0].report.indexOf(this.user_id)
					let templist = res.result.data[0].report.splice(tempindex, 1)
					console.log(tempindex, templist, res.result.data[0].report)
					db.collection("video-articles").where({
						_id: this.vide_id

					}).update({
						report: res.result.data[0].report
					}).then(res=>{
						uni.hideLoading()
						uni.showToast({
							title:"取消成功"
						})
						this.videolist=this.videolist.filter(item=>{
							return item._id!=this.vide_id
						})
						if(this.videolist.length==0){
							this.isshow=true
						}
					})
				})
			},
			getlist() {
				let video = db.collection("video-articles").field(
					'user_id,view_count,publish_date,content,title,report,avatar').getTemp()
				let user = db.collection('uni-id-users').field('_id,avatar,nickname').getTemp()

				db.collection(video, user).where(`report=='${uniCloud.getCurrentUserInfo().uid}'`).get().then(res => {
						
					if(res.result.data.length==0){
						this.isshow=true
					}
					this.videolist = res.result.data
					console.log(res, "那")
				})

			},

			deletevideo(e) {
				this.immediate = true
				console.log(e)
				this.vide_id = e[0]
				this.content = e[1]
			}
		},






	}
</script>

<style lang="scss" scoped>
	
.box{
		
	.pb{
		margin-top: 50rpx;
		display: flex;
		justify-content: center;
		font-size: 40rpx;
		color:#F2E8CF;
		font-family: '楷体';
		font-weight: 700;
	}
}
</style>
<style>
	page {
		background-color: #11265c;
	}
</style>